diff --git a/CMakeLists.txt b/CMakeLists.txt
index bb6c670..5141263 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,8 +30,8 @@ if (PkgConfig_FOUND)
 		pkg_check_modules(GTK2 gtk+-2.0>=2.24)
 		pkg_check_modules(GioUnix gio-unix-2.0>=2.24)
 	endif()
-	pkg_search_module(Lua lua5.4-c++>=5.4 lua5-c++>=5.4 lua5.3-c++>=5.3 lua5-c++>=5.3 lua-c++>=5.3 lua5.2-c++>=5.2 lua-c++>=5.2)
-	pkg_check_modules(Expat expat>=1.0)
+	pkg_search_module(Lua lua5.4>=5.4 lua5>=5.4 lua5.3>=5.3 lua5>=5.3 lua>=5.3 lua5.2>=5.2 lua>=5.2)
+    pkg_check_modules(Expat expat>=1.0)
 endif()
 set(THREADS_PREFER_PTHREAD_FLAG ON)
 find_package(Threads REQUIRED)
diff --git a/source/ColorSpaceType.cpp b/source/ColorSpaceType.cpp
index 8f5d124..a1c0c22 100644
--- a/source/ColorSpaceType.cpp
+++ b/source/ColorSpaceType.cpp
@@ -22,7 +22,9 @@
 #include "lua/Color.h"
 #include "lua/Script.h"
 #include "lua/Callbacks.h"
+extern "C" {
 #include <lua.h>
+}
 #include <iostream>
 using namespace std;
 
diff --git a/source/Converter.cpp b/source/Converter.cpp
index ee9d7d7..9e82b34 100644
--- a/source/Converter.cpp
+++ b/source/Converter.cpp
@@ -33,8 +33,10 @@
 #include <vector>
 #include <iostream>
 #include <functional>
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 using namespace std;
 Converter::Converter(const char *name, const char *label, lua::Ref &&serialize, lua::Ref &&deserialize):
 	m_name(name),
diff --git a/source/GlobalState.cpp b/source/GlobalState.cpp
index ca6542b..c848141 100644
--- a/source/GlobalState.cpp
+++ b/source/GlobalState.cpp
@@ -37,8 +37,10 @@
 #include <filesystem>
 #include <stdlib.h>
 #include <glib/gstdio.h>
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 #include <fstream>
 #include <iostream>
 struct GlobalState::Impl {
diff --git a/source/layout/Layout.cpp b/source/layout/Layout.cpp
index c81a927..6ba7bf9 100644
--- a/source/layout/Layout.cpp
+++ b/source/layout/Layout.cpp
@@ -20,8 +20,10 @@
 #include "System.h"
 #include "../lua/Layout.h"
 #include <iostream>
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 using namespace std;
 namespace layout
 {
diff --git a/source/lua/Color.cpp b/source/lua/Color.cpp
index 724831a..47d6bf4 100644
--- a/source/lua/Color.cpp
+++ b/source/lua/Color.cpp
@@ -18,8 +18,10 @@
 
 #include "Color.h"
 #include "../Color.h"
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 namespace lua
 {
 static int newColor(lua_State *L)
diff --git a/source/lua/ColorObject.cpp b/source/lua/ColorObject.cpp
index a1971b5..19f15e6 100644
--- a/source/lua/ColorObject.cpp
+++ b/source/lua/ColorObject.cpp
@@ -20,8 +20,10 @@
 #include "Color.h"
 #include "Script.h"
 #include "../ColorObject.h"
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 namespace lua
 {
 static int newColorObject(lua_State *L)
diff --git a/source/lua/DynvSystem.cpp b/source/lua/DynvSystem.cpp
index ff3508c..dfbba25 100644
--- a/source/lua/DynvSystem.cpp
+++ b/source/lua/DynvSystem.cpp
@@ -17,8 +17,10 @@
  */
 
 #include "DynvSystem.h"
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 namespace lua {
 dynv::Ref checkDynvSystem(lua_State *L, int index) {
 	void *ud = luaL_checkudata(L, index, "dynvSystem");
diff --git a/source/lua/Extensions.cpp b/source/lua/Extensions.cpp
index 62c6c1b..6e14e84 100644
--- a/source/lua/Extensions.cpp
+++ b/source/lua/Extensions.cpp
@@ -31,8 +31,10 @@
 #include "../Converters.h"
 #include "../Converter.h"
 #include "version/Version.h"
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 namespace lua
 {
 static void checkArgumentIsFunctionOrNil(lua_State *L, int index)
diff --git a/source/lua/GlobalState.cpp b/source/lua/GlobalState.cpp
index 8908538..984bb91 100644
--- a/source/lua/GlobalState.cpp
+++ b/source/lua/GlobalState.cpp
@@ -18,8 +18,10 @@
 
 #include "GlobalState.h"
 #include "../GlobalState.h"
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 namespace lua
 {
 void setGlobalState(lua_State *L, GlobalState &global_state)
diff --git a/source/lua/I18N.cpp b/source/lua/I18N.cpp
index 6791c97..f7fd0e6 100644
--- a/source/lua/I18N.cpp
+++ b/source/lua/I18N.cpp
@@ -18,8 +18,10 @@
 
 #include "I18N.h"
 #include "../I18N.h"
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 namespace lua
 {
 int getText(lua_State *L)
diff --git a/source/lua/Layout.cpp b/source/lua/Layout.cpp
index be83686..b2dfd2b 100644
--- a/source/lua/Layout.cpp
+++ b/source/lua/Layout.cpp
@@ -23,8 +23,10 @@
 #include "../layout/Box.h"
 #include "../layout/System.h"
 #include "../layout/Layout.h"
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 #include <typeinfo>
 #include <iostream>
 using namespace std;
diff --git a/source/lua/Ref.cpp b/source/lua/Ref.cpp
index 9b1acc7..96c108f 100644
--- a/source/lua/Ref.cpp
+++ b/source/lua/Ref.cpp
@@ -17,8 +17,10 @@
  */
 
 #include "Ref.h"
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 namespace lua
 {
 Ref::Ref():
diff --git a/source/lua/Script.cpp b/source/lua/Script.cpp
index a39e3eb..6358327 100644
--- a/source/lua/Script.cpp
+++ b/source/lua/Script.cpp
@@ -18,8 +18,10 @@
 
 #include "Script.h"
 #include <sstream>
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 #include <iostream>
 using namespace std;
 namespace lua
diff --git a/source/test/Script.cpp b/source/test/Script.cpp
index 8fdeaa9..55a6c3e 100644
--- a/source/test/Script.cpp
+++ b/source/test/Script.cpp
@@ -19,8 +19,10 @@
 #include <boost/test/unit_test.hpp>
 #include "lua/Script.h"
 #include "common/Scoped.h"
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 using namespace lua;
 static int test(lua_State *L) {
 	lua_pushstring(L, "ok");
diff --git a/source/uiDialogOptions.cpp b/source/uiDialogOptions.cpp
index e70debb..b072944 100644
--- a/source/uiDialogOptions.cpp
+++ b/source/uiDialogOptions.cpp
@@ -28,8 +28,10 @@
 #include "lua/Callbacks.h"
 #include <string>
 #include <iostream>
+extern "C" {
 #include <lualib.h>
 #include <lauxlib.h>
+}
 using namespace std;
 static const struct{
 	const char *label;
